package cn.yql8.interceptor;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AppInterceptor extends HandlerInterceptorAdapter{
	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
		Cookie[] cookieArr = request.getCookies();
		if(cookieArr != null){
			for(int i=0; i<cookieArr.length; i++){
				Cookie cookie = cookieArr[i];
				System.out.println("f:" + cookie.getName());
				System.out.println("c:" + cookie.getValue());
			}
		}
		Cookie cookie = new Cookie("lastModifyTime",System.currentTimeMillis()/1000 + "");
		cookie.setDomain(".test.com");
		cookie.setPath("/");
		response.addCookie(cookie);
		return super.preHandle(request, response, handler);
	}
}
